<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_areashoplive/model')->方法名();
*/
namespace jy_areashoplive;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function get_area_code($area){
		$areaset=plugin('jy_area_agent')->plugin_setting('setting');
		if($areaset['level']==1){
			$title=$pcd['province'];
			$levelpcd=array(
				'province'=>$pcd['province']
			);
		}elseif($areaset['level']==2){
			$title=$pcd['city'];
			$levelpcd=array(
				'province'=>$pcd['province'],
				'city'=>$pcd['city'],
			);
		}elseif($areaset['level']==3){
			$title=$pcd['district'];
			$levelpcd=array(
				'province'=>$pcd['province'],
				'city'=>$pcd['city'],
				'district'=>$pcd['district'],
			);
		}elseif($areaset['level']==4){
			$title=$pcd['street'];
			$levelpcd=array(
				'province'=>$pcd['province'],
				'city'=>$pcd['city'],
				'district'=>$pcd['district'],
				'street'=>$pcd['street'],
			);
		}
		if(!$levelpcd){
			return false;
		}
		$address=$area['province'];
		if($area['city']){
			$address.=' '.$area['city'];
		}
		if($area['district']){
			$address.=' '.$area['district'];
		}
		if($area['street']){
			$address.=' '.$area['street'];
		}
		$area_code=pdo_getcolumn('core_area',array('address'=>$address),'code');
		if($_SESSION['uid']){
			$myarea_code=pdo_getcolumn('jy_weishop_member',array('mid'=>$_SESSION['uid']),'area_code');
			if(!$myarea_code !=$area_code){
				pdo_update('jy_weishop_member',array('area_code'=>$area_code),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
			}
		}
		$data=array(
			'area_code'=>$area_code,
			'address'=>$address,
			'title'=>$title,
		);
		return $data;
	}
}
?>